<?
	  	  include("/inc/header.html") {}
    ?>
  <br>
<div class="content_wrap">
	<div class="zTreeDemoBackground left">
 &nbsp;&nbsp;&nbsp;<input id="citySel" type="text"  readonly value="" style="width:300px;" onclick="showMenu();" />
 
	</div>
	
</div>
<input id="domainid" type="hidden"  class="form-control" />

<div id="menuContent" class="menuContent" >
	<ul id="treeDemo" class="ztree" style="margin-top:0; width:180px; height: 300px;"></ul>
</div>

<script>
	//所属  字典类Id
	//树状结构
	function getQueryString(name) { 
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
	var r = window.location.search.substr(1).match(reg); 
	if (r != null) return unescape(r[2]); return null; 
	} 
	var winName=getQueryString("winName");
	var idv;
	$(function() {
		initTree();
	});
	function initTree() {
		$.ajax({
			type : "post",
			data : {},
			url : "domainCategoryZTree.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTree,
		});
	}
	function drawTree(data) {
		var setting = {
			check: {
				enable: true,
				chkboxType: {"Y":"", "N":""}
			},
			view: {
				dblClickExpand: false
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				beforeClick: beforeClick,
				onCheck: onCheck
			}
		};
		var zNodes = eval(data);
		$.fn.zTree.init($("#treeDemo"), setting, zNodes).expandAll(true);
		zTree = $.fn.zTree.getZTreeObj("treeDemo");
		zTree.expandNode(zTree.getNodes()[0], true);//指定某节点折叠

	}
	
	function beforeClick(treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			zTree.checkNode(treeNode, !treeNode.checked, null, true);
			return false;
		}
		
		function onCheck(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			nodes = zTree.getCheckedNodes(true),
			v = "";
			for (var i=0, l=nodes.length; i<l; i++) {
				v += nodes[i].name + ",";
			}
			idv = "";
			for (var i=0, l=nodes.length; i<l; i++) {
				idv += nodes[i].id + ",";
			}
			if (v.length > 0 ) v = v.substring(0, v.length-1);
			if (idv.length > 0 ) idv = idv.substring(0, idv.length-1);
			var cityObj = $("#citySel");
			cityObj.attr("value", v);
			
			var cityObj = $("#domainid");
			cityObj.attr("value", idv);
			
		
		}
function  save(){
var index = parent.layer.getFrameIndex(window.name);
     if(idv==null)
     {
       window.parent.window[winName].$("#mainid").val("");
	    window.parent.window[winName].$("#domainname").val("");
	    parent.layer.close(index);
	    }
	    else{
	     window.parent.window[winName].$("#mainid").val(idv);
	     window.parent.window[winName].$("#domainname").val($("#citySel").val());
	    parent.layer.close(index);
	    }
}
		function showMenu() {
			var cityObj = $("#citySel");
			var cityOffset = $("#citySel").offset();
			$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");

			$("body").bind("mousedown", onBodyDown);
		}
		function hideMenu() {
			$("#menuContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "citySel" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
				hideMenu();
			}
		}
	
	
</script>